package com.yanze.schoolinformation.adapter;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.yanze.schoolinformation.R;
import com.yanze.schoolinformation.databinding.ItemHomeMenuBinding;
import com.yanze.schoolinformation.model.bean.HomeMenuBean;

import java.util.List;

/**
 * 首页菜单适配器
 * Created by MrZheng on 2018/3/23.
 */

public class HomeMenuAdapter extends RecyclerView.Adapter {
    private List<HomeMenuBean> mDatas;

    public HomeMenuAdapter(List<HomeMenuBean> datas){
        this.mDatas = datas;
    }

    public class MenuViewHolder extends RecyclerView.ViewHolder {
        private ItemHomeMenuBinding binding;

        public MenuViewHolder(ItemHomeMenuBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemHomeMenuBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_home_menu, parent, false);
        MenuViewHolder holder = new MenuViewHolder(binding);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((MenuViewHolder) holder).binding.setMenu(mDatas.get(position));
        ((MenuViewHolder) holder).binding.executePendingBindings();
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }
}
